#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QtNetwork>
#include <QMessageBox>
#include <QTimer>

namespace Ui {
class Widget;
}

typedef struct protocolHead
{
    unsigned char headFlag[7];
    unsigned char len_h;
    unsigned char len_l;
    unsigned char destId;
    unsigned char srcId;   

    char data[0];
}__attribute__((packed))protocolHead_st;




class Widget : public QWidget
{
    Q_OBJECT
    
public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
    int ascii2Hex(QByteArray *inData, char *outData);
    int sendData(char *pData, int iLen);
    
    int port;
    QHostAddress *serverIP;
    QTcpSocket *tcpSocket;

private slots:
    void on_closeButton_clicked();

    void on_connectButton_clicked();

    void on_sendButton_clicked();

    void on_pushButton_clicked();

    void on_clearSendBuf_clicked();

    void on_allSelectButton_clicked();

    void on_hexRadioButton_clicked();

    void on_asciiRadioButton_2_clicked();

    void on_sendMsg_textEdited(const QString &arg1);

    void on_sendMsg_textChanged(const QString &arg1);

    void on_checkBox_clicked();

    void on_checkBox_clicked(bool checked);

    void on_setDebugLevel_clicked();

public slots:

    void dataReceived();
    void slotDisconnected();
    void slotConnected();
    void TimerSendData();

private:
    Ui::Widget *ui;
    bool bConnectFlag;
    bool bHexMod; //true=Hex mode ; false=Ascii mode
    QTimer m_sendTimer;
    char bagId;
};

#endif // WIDGET_H
